﻿using Newtonsoft.Json.Linq;
using Simple.Tools.Entity;
using Simple.Tools.Extensions;
using System;
using System.Reflection;
using System.Text.RegularExpressions;

namespace Simple.Tools.Verify
{
   /// <summary>
   /// 可以应用于常见字符串
   /// 必须填写验证特性
   /// </summary>
    public class CusRequiredAttribute : BaseVerifyAttribute
    {
        private double _max;
        private double _min;
		private BaseCheckType _checkType;
	
		/// <summary>
		/// 
		/// </summary>
		/// <param name="propName"></param>
		/// <param name="max"></param>
		/// <param name="min"></param>
		public CusRequiredAttribute(string propName,double max=-1,double min=-1):base(propName)
        {
			init(max,min);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="max"></param>
		/// <param name="min"></param>
		public void init(double max=-1,double min=-1)
		{
			this._checkType = SimpleInitialize.GetCheckType();
			this._errorInfo = "为必填项!";
			this._max = max;
			this._min = min;
		}
		protected override string GetErrorInfo()
        {
            return base.GetErrorInfo();
        }
		/// <summary>
		/// item1 msg 
		/// false 表示验证不合法
		/// </summary>
		/// <param name="o"></param>
		/// <param name="prop"></param>
		/// <returns></returns>
		public override Tuple<string, bool> Verify(object o,PropertyInfo prop)
        {
			if (SimpleCheck.IsNull(o))
			{
				return Tuple.Create(GetErrorInfo(), false);
			}

			object targetValue = prop.GetValue(o);
			bool result = false;
			if (SimpleCheck.IsNull(targetValue) || SimpleCheck.IsNullOrEmpty(targetValue.ToString()))
			{
				return Tuple.Create(GetErrorInfo(), result);
			}
			result = true;
            return Tuple.Create(GetErrorInfo(), result);
        }
    }
}
